package cn.edu.sjtu.se.dslab.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import cn.edu.sjtu.se.dslab.component.data.DataEntity;
import cn.edu.sjtu.se.dslab.component.data.Operation;
import cn.edu.sjtu.se.dslab.dao.IBaseDao;
import cn.edu.sjtu.se.dslab.dao.IOperationDao;

@Repository("operationDao")
public class OperationDaoImpl implements IOperationDao {

	@Resource(name = "baseDao")
	private IBaseDao<Operation> baseDao;

	@Override
	public void save(Operation operation) {
		// TODO Auto-generated method stub
		baseDao.save(operation);
	}

	@Override
	public void update(Operation operation) {
		// TODO Auto-generated method stub
		baseDao.update(operation);
	}

	@Override
	public Operation queryById(long id) {
		// TODO Auto-generated method stub
		return baseDao.queryById(Operation.class, id);
	}

	@Override
	public List<Operation> queryByDataEntity(DataEntity entity) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer();

		// 拼接sql语句
		hql.append("from Operation c where ");
		hql.append( " c.entity.id = ");
		hql.append("" + entity.getId());
		return baseDao.query(hql.toString());
	}

}
